﻿
using System;
using System.Collections;
using System.Collections.Generic;

namespace Test30.Engine
{
    public class Stats : IList<Stat>
    {
        //力量
        public Strength Strength => _strength;
        //敏捷
        public Agility Agility => _agility;
        //耐力
        public Stamina Stamina => _stamina;
        //愿力
        public Will Will => _will;
        //智力
        public Intellect Intellect => _intellect;
        //魅力
        public Charisma Charisma => _charisma;

        public Stat this[int index]
        {
            get
            {
                switch (index)
                {
                    case 0: return _strength;
                    case 1: return _agility;
                    case 2: return _stamina;
                    case 3: return _will;
                    case 4: return _intellect;
                    case 5: return _charisma;
                    default: throw new ArgumentOutOfRangeException(nameof(index));
                }
            }
            set => throw new NotSupportedException();
        }
        public Stats()
        {
            foreach (Stat stat in this)
            {
                stat.Base = 5;
            }

            for (int i = 0; i < 10 * Count; i++)
            {
                Rng.Item(this).Base++;
            }
        }

        public IEnumerator<Stat> GetEnumerator()
        {
            for (int i = 0; i < Count; i++)
            {
                yield return this[i];
            }
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        public void Add(Stat item)
        {
            throw new NotSupportedException();
        }

        public void Clear()
        {
            throw new NotSupportedException();
        }

        public bool Contains(Stat item) => throw new NotImplementedException();

        public void CopyTo(Stat[] array, int arrayIndex) => throw new NotImplementedException();

        public bool Remove(Stat item)
        {
            throw new NotSupportedException();
        }

        public int Count => 6;
        public bool IsReadOnly => true;
        public int IndexOf(Stat item)
        {
            for (int i = 0; i < Count; i++)
            {
                if (this[i] == item) return i;
            }

            return -1;
        }

        public void Insert(int index, Stat item)
        {
            throw new NotSupportedException();
        }

        public void RemoveAt(int index)
        {
            throw new NotSupportedException();
        }


        private readonly Strength _strength = new Strength();
        private readonly Agility _agility = new Agility();
        private readonly Stamina _stamina = new Stamina();
        private readonly Will _will = new Will();
        private readonly Intellect _intellect = new Intellect();
        private readonly Charisma _charisma = new Charisma();

    }

    public class Strength : Stat
    {
        public float DamageBonus => StatTable.GetPointOneToTen(Current);
    }
    public class Agility : Stat
    {
        public int StrikeBonus => StatTable.GetNegativeFiftyToHundred(Current);
    }

    public class Stamina : Stat
    {
        public int MaxHealth => (int)StatTable.GetFiveToTwoHundred(Current);
    }
    public class Will : Stat
    {
        public bool ResistDrain()
        {
            //### bob enemy will should affect
            return Rng.Int(100) < Current;
        }
    }
    public class Intellect : Stat
    {
    }
    public class Charisma : Stat
    {
        public float BuyPriceMultiplier => 1.0f / StatTable.GetPointFiveToTwo(Current);
        public float SellPriceMultiplier => StatTable.GetPointFiveToTwo(Current);
    }
}
